package com.hello.sandbox.fake.service;

import android.content.Context;
import black.android.content.pm.BRILauncherAppsStub;
import black.android.os.BRServiceManager;
import java.lang.reflect.Method;
import com.hello.sandbox.fake.hook.BinderInvocationStub;
import com.hello.sandbox.utils.MethodParameterUtils;

/** Created by Milk on 4/13/21. * ∧＿∧ (`･ω･∥ 丶　つ０ しーＪ 此处无Bug */
public class ILauncherAppsProxy extends BinderInvocationStub {

  public ILauncherAppsProxy() {
    super(BRServiceManager.get().getService(Context.LAUNCHER_APPS_SERVICE));
  }

  @Override
  protected Object getWho() {
    return BRILauncherAppsStub.get()
        .asInterface(BRServiceManager.get().getService(Context.LAUNCHER_APPS_SERVICE));
  }

  @Override
  protected void inject(Object baseInvocation, Object proxyInvocation) {
    replaceSystemService(Context.LAUNCHER_APPS_SERVICE);
  }

  @Override
  public boolean isBadEnv() {
    return false;
  }

  @Override
  protected void onBindMethod() {
    super.onBindMethod();
  }

  @Override
  public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    MethodParameterUtils.replaceFirstAppPkg(args);
    // todo shouldHideFromSuggestions
    return super.invoke(proxy, method, args);
  }
}
